package com.cty.kafka.service.mq.listener;

import com.alibaba.fastjson.JSON;
import com.cty.kafka.common.bo.User;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * HelloListener
 *
 * @author tianyuchan
 * @since 2024/7/13
 */

@Component
public class HelloListener {

    @KafkaListener(topics = "hello-topic")
    public void onMessageHello(String message){
        if(!StringUtils.isEmpty(message)){
            System.out.println(message);
        }
    }

    @KafkaListener(topics = "user-topic")
    public void onMessageUser(String message){
        if(!StringUtils.isEmpty(message)){
            User user = JSON.parseObject(message, User.class);
            System.out.println("name = " + user.getName());
            System.out.println("age = " + user.getAge());
        }
    }
}
